//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "uLetAuto.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CEdit"
#pragma link "CCheckB"
#pragma link "CRadBtn"
#pragma link "CBitBtn"
#pragma resource "*.dfm"
//---------------------------------------------------------------------------
__fastcall TfrmLettrageAuto::TfrmLettrageAuto( TComponent* Owner, TYPE_LETTRAGE tLettrage, int Recurs /* = NULL */)
    : CForm(Owner)
{
  lblCompte  ->Caption = EmptyStr;
  lblLettrage->Caption = EmptyStr;
  lblLetFind ->Caption = "0";
  m_eTraitement       = TL_WAIT;
  switch (tLettrage)
  {
    case LETTRAGE_PIECE_INTERNE:
      rbPieceInterne->Checked = true;
      break;
    case LETTRAGE_PIECE_EXTERNE:
      rbPieceExterne->Checked = true;
      break;
    case LETTRAGE_COMPTES_SOLDES:
      rbSoldes->Checked = true;
      break;
    case LETTRAGE_COMBINATOIRE:
      rbCombinatoire->Checked = true;
      udRecurs->Position =  Recurs;
      break;
  }
}
//---------------------------------------------------------------------------
void __fastcall TfrmLettrageAuto::btnLettrerClick(TObject *Sender)
{
  btnLettrer->Enabled = false;
  udRecurs  ->Enabled = false;
  m_eTraitement       = TL_LETTRER;
  Refresh();
  btnAnnuler->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfrmLettrageAuto::btnAnnulerClick(TObject *Sender)
{
   m_eTraitement = TL_ABORT;
}
//---------------------------------------------------------------------------
void __fastcall TfrmLettrageAuto::SetCompte( const AnsiString &strCompte)
{
  m_nLettrage         = 0;
  Inc();
  pbDebits ->Position = 0;
  pbCredits->Position = 0;
  lblLetFind->Caption = IntToStr( m_nLettrage);
  InfoCompte = strCompte;
  Refresh();
}
//---------------------------------------------------------------------------
int  __fastcall TfrmLettrageAuto::GetRecursion() const
{
  return udRecurs->Position;
}
//---------------------------------------------------------------------------
void __fastcall TfrmLettrageAuto::DebutLettrage()
{
  lblLetFind ->Caption = IntToStr( ++m_nLettrage);
  lblLettrage->Caption = "Lettrage en cours ...";
  Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TfrmLettrageAuto::FinLettrage()
{
  lblLettrage->Caption = EmptyStr;
  Refresh();
}
//---------------------------------------------------------------------------

void __fastcall TfrmLettrageAuto::rbCombinatoireCheck(TObject *Sender, bool bIsChecked)
{
  edRecurs->Enabled = rbCombinatoire->Checked;
  udRecurs->Enabled = edRecurs->Enabled;
  Label1->Enabled   = edRecurs->Enabled;
  Label2->Enabled = rbCombinatoire->Checked;
  Label3->Enabled = rbCombinatoire->Checked;
}
//---------------------------------------------------------------------------

void __fastcall TfrmLettrageAuto::FormCloseQuery(TObject *Sender, bool &CanClose)
{
  if (m_eTraitement       == TL_WAIT)
    m_eTraitement = TL_ABORT;
}
//---------------------------------------------------------------------------

